package local.blueheart.data.springdatademo.repository.archive;

import local.blueheart.data.springdatademo.domain.archive.ArchiveIndexData;
import local.blueheart.data.springdatademo.domain.archive.ArchivedServerDBData;
import local.blueheart.data.springdatademo.domain.archive.DocCompositedId;
import local.blueheart.data.springdatademo.domain.config.ModuleDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface ArchiveIndexRepository  extends JpaRepository<ArchiveIndexData, DocCompositedId> {


    @Query("select new local.blueheart.data.springdatademo.domain.archive.ArchivedServerDBData(a.mainDocumentServer,a.dbPath,a.applicationDO,a.moduleDO) from ArchiveIndexData as a where a.mainDocumentServer<>'' group by a.mainDocumentServer,a.dbPath,a.applicationDO,a.moduleDO")
    List<ArchivedServerDBData> findAllDataDbList();


    @Query("select t from ArchiveIndexData t where t.mainDocumentServer=:serverName and t.dbPath=:dbPath and t.moduleDO=:moduleDO and t.status=:status")
    List<ArchiveIndexData> findByMainDocumentServerAndDbPathAndModuleDOAndStatus(@Param("serverName") String serverName,@Param("dbPath") String dbPath,@Param("moduleDO") ModuleDO moduleDO,@Param("status") String status);

}
